/*
 * migrarcuentascontables.java
 *
 * Created on 23 de agosto de 2007, 13:32
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package utiles;
import java.sql.*;  
 import java.io.*;  
 import com.hxtt.sql.*;
 import java.rmi.*;
 import java.rmi.registry.*;
 import java.rmi.registry.LocateRegistry;
/**
 *
 * @author admin
 */
public class migrar{
    funcioncliente.FuncionesControlAcceso fca;
    String conexao = "com.hxtt.sql.dbf.DBFDriver"; 
    utiles.ModificableTableModel modelo;
    Statement stmt;
    Connection conn;
    DatosTablaDBF dbb;
    utiles.conexionRmiJdbc conex;
     ResultSet result;
    /** Creates a new instance of migrarcuentascontables */
    public migrar() {
         try{
            
        System.setProperty("java.security.policy", "c:/java.policy");
        System.setProperty ("java.rmi.server.codebase","http://192.168.23.6/");
        
        if (System.getSecurityManager() == null){
 		System.setSecurityManager(new RMISecurityManager());
 		}
            fca=( funcioncliente.FuncionesControlAcceso)java.rmi.Naming.lookup("//192.168.23.6:1234/rmi");
                 
            
        }catch(Exception e){
            e.printStackTrace();
        }
           try{
            Class.forName(conexao).newInstance();
            String url = "jdbc:DBF:/c:/dbf/";
            conn = DriverManager.getConnection(url);
            stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
                                                          java.sql.ResultSet.CONCUR_UPDATABLE);
        }catch(Exception e){}
        conex=new utiles.conexionRmiJdbc("192.168.23.6","SQL2005","RecursosHumanos","administrador","administrador1234",true);
        this.migUnidades();
        //this.migcodPresupuestal();
        //this.migLocalidades();
        //this.migCentrosCostos();
    
    }
    
    void migcodPresupuestal(){
        try{
            result=stmt.executeQuery("select LLAVE, DESCRIP  from TAB_ACTI");
            result.last();
            int num=result.getRow();    
            String par1=null,par2=null, par3 = null;
            for(int i=0;i<num;i++){
                result.absolute(i+1);
                try{            
                    par1=result.getString(1).trim();                    
                }catch(Exception e1){                    
                    e1.printStackTrace();
                }
                 try{
                    par2=result.getString(2).trim();
                    System.out.println("Parametros: "+par1+"   "+par2);                    
                }catch(Exception e2){                    
                    e2.printStackTrace();
                }                                
               PreparedStatement pstmt = conex.conexion.prepareStatement("insert into cod_presupuestal" +
                        " (id_cod_presupuestal, desc_cod_presupuestal) values (?,?)");
                pstmt.setString(1,par1.trim());
                pstmt.setString(2,par2.trim());
                //pstmt.setString(3,par3);
                pstmt.executeUpdate();
                pstmt.close();
                conex.conexion.commit();            
            }            
            result.close();
        }catch(Exception efg){
            System.out.println("en RMi  ");
            efg.printStackTrace();
        }
    }  
    void migLocalidades(){
        try{                
            //result=stmt.executeQuery("select COD_LOCAL ,DES_LOCAL,COD_ZONA  from LOCALIDAD");
            result=stmt.executeQuery("select * from LOCALIDAD");
            result.last();
            int num=result.getRow();    
            String par1=null,par2=null, par3 = null;
            for(int i=0;i<num;i++){
                result.absolute(i+1);
                try{                    
                    par1=result.getString(1).trim();                    
                }catch(Exception e1){
                    System.out.println("en param1: "+par1);
                    e1.printStackTrace();
                }
                 try{
                    par2=result.getString(2).trim();
                }catch(Exception e2){
                    System.out.println("en param2:  "+par2);
                    e2.printStackTrace();
                }
                try{
                    par3=result.getString(3).trim();                    
                }catch(Exception e3){                    
                    e3.printStackTrace();
                }   
                System.out.println("Parametros: "+par1+"   "+par2+"  "+par3);
               /*PreparedStatement pstmt = conex.conexion.prepareStatement("insert into localidad" +
                        " (id_localidad, nom_localidad,id_zona) values (?,?,?)");
                pstmt.setString(1,par1.trim());
                pstmt.setString(2,par2.trim());
                pstmt.setString(3,par3);
                pstmt.executeUpdate();
                pstmt.close();
                conex.conexion.commit();            */
            }
            result.close();
        }catch(Exception efg){
            System.out.println("en RMi  ");
            efg.printStackTrace();
        }
    }
    void migUnidades(){
        try{                
            //result=stmt.executeQuery("select COD_LOCAL ,DES_LOCAL,COD_ZONA  from LOCALIDAD");
            result=stmt.executeQuery("select COD_UNIDAD,DES_UNIDAD from UNIDAD");
            result.last();
            int num=result.getRow();    
            String par1=null,par2=null; 
            for(int i=0;i<num;i++){
                result.absolute(i+1);
                try{                    
                    par1=result.getString(1).trim();                    
                }catch(Exception e1){
                    System.out.println("en param1: "+par1);
                    e1.printStackTrace();
                }
                 try{
                    par2=result.getString(2).trim();
                }catch(Exception e2){
                    System.out.println("en param2:  "+par2);
                    e2.printStackTrace();
                }                   
                System.out.println("Parametros: "+par1+"   "+par2+"  ");
               /*PreparedStatement pstmt = conex.conexion.prepareStatement("insert into localidad" +
                        " (id_localidad, nom_localidad,id_zona) values (?,?,?)");
                pstmt.setString(1,par1.trim());
                pstmt.setString(2,par2.trim());
                pstmt.setString(3,par3);
                pstmt.executeUpdate();
                pstmt.close();
                conex.conexion.commit();            */
            }
            result.close();
        }catch(Exception efg){
            System.out.println("en RMi  ");
            efg.printStackTrace();
        }
    }
    void migCentrosCostos(){
        try{                
            result=stmt.executeQuery("select CCTA ,DESC ,PRESUPUEST  from PLANCTOS");
            //result=stmt.executeQuery("select *  from PLANCTOS");
            result.last();
            int num=result.getRow();    
            String par1=null,par2=null, par3 = null;
            for(int i=0;i<num;i++){
                result.absolute(i+1);
                try{                    
                    par1=result.getString(1).trim();                    
                }catch(Exception e1){
                    System.out.println("en param1: "+par1);
                    e1.printStackTrace();
                }
                 try{
                    par2=result.getString(2).trim();
                }catch(Exception e2){
                    System.out.println("en param2:  "+par2);
                    e2.printStackTrace();
                }
                try{
                    par3=result.getString(3).trim();                    
                }catch(Exception e3){                    
                    e3.printStackTrace();
                }   
                System.out.println("Parametros: "+par1+"   "+par2+"  "+par3);
               /*PreparedStatement pstmt = conex.conexion.prepareStatement("insert into localidad" +
                        " (id_localidad, nom_localidad,id_zona) values (?,?,?)");
                pstmt.setString(1,par1.trim());
                pstmt.setString(2,par2.trim());
                pstmt.setString(3,par3);
                pstmt.executeUpdate();
                pstmt.close();
                conex.conexion.commit();            */
            }
            result.close();
        }catch(SQLException efg){
            System.out.println("en RMi  ");
            efg.getNextException().toString();
            efg.printStackTrace();
        }
    }
    public static void main(String args[]){
        new  migrar();
    }
    
}
